from typing import Optional

from sqlalchemy import Integer
from sqlmodel import Field

from src.base.beans import PageParam
from src.base.enums import DataScopeType
from src.domain.base_model import TenantModel


class SysRoleBase(TenantModel):
    role_id: Optional[int] = Field(primary_key=True, description="角色序号", sa_column_kwargs={"comment": "角色序号"})
    role_name: Optional[str] = Field(description="角色名称", sa_column_kwargs={"comment": "角色名称"})
    role_code: Optional[str] = Field(description="角色编码", sa_column_kwargs={"comment": "角色编码"})
    data_scope: Optional[DataScopeType] = Field(description="数据权限范围", sa_type=Integer,
                                                sa_column_kwargs={"comment": "数据权限范围", "server_default": "5"})
    custom_dept: Optional[str] = Field(default=False, description="自定义部门权限",
                                       sa_column_kwargs={"comment": "自定义部门权限"})
    custom_user: Optional[str] = Field(default=False, description="自定义用户权限",
                                       sa_column_kwargs={"comment": "自定义用户权限"})


class SysRole(SysRoleBase, table=True):
    __tablename__ = "sys_role"
    __table_args__ = {'extend_existing': True, 'comment': '角色表'}


class SysRoleReq(SysRoleBase, PageParam):
    pass


class SysRoleResp(SysRoleBase):
    pass
